﻿@{
    Layout = "~/Areas/Web/Views/Shared/_UserCenter.cshtml";
    ViewBag.Title = "退换货列表";
}
@model  IEnumerable<Himall.Model.OrderComplaintInfo>
@using Himall.Core;

<div class="box1 lh24">
    <div class="title">
        <span class="title_txt"><a href="@Url.Action("Index")">投诉维权</a></span>
        <span class="title_txt curr">申请记录</span>
    </div>
    <div class="border-box">
        <table class="tb-void tb-back">
            <colgroup>
                <col width="350" />
                <col width="100" />
                <col width="80" />
                <col width="120" />
                <col width="100" />
                <col width="100" />
            </colgroup>
            <thead>
                <tr class="tr">
                    <th>投诉内容</th>
                    <th>联系电话</th>
                    <th>所属订单</th>
                    <th>提交时间</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                @if (Model.Count() == 0)
                {
                    <tr><td colspan="6"><div class="empty"><b></b>暂时没有记录</div></td></tr>
                }
                @foreach (var m in Model)
                {
                    <tr class="tr-td">
                        <td><span class="col-blue" title="@m.ComplaintReason" style="height:18px; overflow:hidden;text-overflow:ellipsis;white-space:nowrap; width:350px">@m.ComplaintReason</span></td>
                        <td><span class="col-blue">@m.UserPhone</span></td>
                        <td>@m.OrderId</td>
                        <td>@m.ComplaintDate</td>
                        <td>@m.Status.ToDescription()</td>
                        <td>
                            <span style="display:none">@m.SellerReply</span>
                            @if (m.Status == Himall.Model.OrderComplaintInfo.ComplaintStatus.WaitDeal)
                            {
                                <a cid="@m.Id" deal="cancel" class="complain-btn">取消</a>
                            }
                            else if (m.Status == Himall.Model.OrderComplaintInfo.ComplaintStatus.Dealed)
                            {
                                <a cid="@m.Id" deal="ok" class="complain-btn">满意</a>
                            }
                            @if (m.Status == Himall.Model.OrderComplaintInfo.ComplaintStatus.Dealed || m.ComplaintDate.AddDays(1) < DateTime.Now && m.Status == Himall.Model.OrderComplaintInfo.ComplaintStatus.WaitDeal)
                            {
                                <a cid="@m.Id" deal="bad" class="complain-btn">申请仲裁</a>
                            }
                        </td>
                    </tr>
                }
            </tbody>
        </table>
		<div class="mt10">
			<div id="pagin-btm" class="pagin fr" style="clear:both">
				@{
					var count = ((PagingInfo)ViewBag.pageInfo).TotalPages;
					var curr = ((PagingInfo)ViewBag.pageInfo).CurrentPage;
				}
				@Html.PageLinks((PagingInfo)ViewBag.pageInfo, x => Url.Action("Record", new { pageNo = x }))
				<span class="page-skip">
					<em>&nbsp;&nbsp;共 @count 页&nbsp;&nbsp;&nbsp;&nbsp;</em>
				</span>
			</div>
			<div class="clr"></div>
		</div>
    </div>
    

</div>
<script type="text/javascript">
    var currentId = 0;
    $(function () {
        $('.complain-btn').click(function () {
            currentId = $(this).attr("cid");
            var type = $(this).attr("deal");
            var replyContent = $(this).parent().find("span").html();
            switch (type) {
                case "cancel":
                    $.dialog.confirm("取消此次投诉！", function () { DealComplaint() });
                    break;
                case "ok":
                    $.dialog({
                        title: '对投诉结果满意',
                        lock: true,
                        width: 400,
                        id: 'Agree',
                        content: '<p class="ftx03">商家回复：' + replyContent + '</p><br>是否满意商家的回复？',
                        padding: '20px',
                        cancelVal: '取消',
                        ok: function () {
                            DealComplaint();
                        },
                        cancel: true
                    });
                    break;
                case "bad":
                    $.dialog({
                        title: '申请仲裁',
                        lock: true,
                        width: 400,
                        id: 'goodCheck',
                        content: '<p class="ftx03">商家回复：' + replyContent + '</p><br>是否不满意商家的回复并且进行投诉？',
                        padding: '20px',
                        cancelVal: '取消',
                        ok: function () {
                            ApplyArbitration();
                        },
                        cancel: true
                    });
                    break;
            }
        });
    });
    function DealComplaint() {
        var loading = showLoading();
        $.ajax({
            type: 'post',
            url: '/OrderComplaint/DealComplaint',
            cache: false,
            data: { id: currentId },
            dataType: 'json',
            success: function (data) {
                loading.close();
                if (data.success) {
                    $.dialog.succeedTips("处理成功！", function () {
                        window.location.href = window.location.href;
                    }, 1);
                }
            },
            error: function () { }
        });
    }
    function ApplyArbitration() {
        var loading = showLoading();
        $.ajax({
            type: 'post',
            url: '/OrderComplaint/ApplyArbitration',
            cache: false,
            data: { id: currentId },
            dataType: 'json',
            success: function (data) {
                loading.close();
                if (data.success) {
                    $.dialog.succeedTips("申请成功！", function () {
                        window.location.href = window.location.href;
                    }, 1);
                }
            },
            error: function () { }
        });
    }
</script>